import axios from "./config";

/**登录模块 */
/**
 *
 * @param {string} username 用户名
 * @param {string} password 用户密码
 * @returns promise
 */
// 定义请求接口
export const loginApi = (username, password) =>
  axios.post("/users/login", {
    username,
    password,
  });

//获取验证码
export const getCaptchaApi = () => axios.get("/users/getCaptcha");

//校验验证码
export const verifyCaptcha = (captcha = "") =>
  axios.get("/users/verifyCaptcha", {
    params: {
      captcha,
    },
  });

//获取登录日志
/**
 *
 * @param {string} page 第几页
 * @param {string} count 每页的数量
 * @returns {Promise}
 */
export const getLoginLogApi = (componentInstance, page = 1, count = 15) =>
  axios.get("/getloginlog", {
    params: {
      page,
      count,
    },
  });

// 获取微信二维码url
export const getQrcodeUrlApi = (sid) =>
  axios.get("/users/getQrcode", {
    params: {
      sid,
    },
  });
// 微信登录
export const wechatLoginApi = (wechatCode) =>
  axios.get("/users/wechatLogin", {
    params: {
      wechatCode,
    },
  });

// 获取权限菜单
export const getMenuListApi = () => axios.get("/permission/getMenuList");

/**学员模块 */
// 获取学员列表
/**
 *
 * @param {Number} page 页码
 * @param {Number} count 单页显示的数量
 * @param {String} classes 班级
 * @returns {Promise} 返回一个promise类型的方法
 */
export const getStuListApi = (page = 1, count = 10, classes = "") =>
  axios.get("/students/getstulist", {
    params: {
      page,
      count,
      class: classes,
    },
  });

// 添加学员信息
export const addStuApi = (data) => axios.post("/students/addstu", data);

//修改学员信息
export const updateStuApi = (data) => axios.post("/students/updatestu", data);

//删除学员信息
export const delStuApi = (sId) =>
  axios.get("/students/delstu", {
    params: {
      sId,
    },
  });

// 获取班级列表
export const getClassesApi = () => axios.get("/students/getclasses");

// 搜索学员信息
/**
 *
 * @param {Number} page 初始页码
 * @param {String} key 传入的关键字
 * @param {Number} count 每页显示的学员信息数
 * @returns promise
 */
export const searchStuApi = (page = 1, key = "", count = 10) => {
  // 短路运算
  count = count || 10;
  key = key || "";
  page = page || 1;
  return axios.get("/students/searchstu", {
    params: {
      page,
      count,
      key,
    },
  });
};

//商城模块

// 获取订单
export const getOrderApi = (order_id) => axios.post("/order/get_order");

// 获取产品
/**
 * 
 * @param {String} category_id 商品所在类目的id
 * @returns 
 */
export const getVipListApi = category_id=>axios.get("/product/get_product",{
  params:{
    category_id
  }
})